﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Axial.Tests
{
	[TestFixture]
	class BreakTests : TestBase
	{

		[Test]
		public void BreakTest()
		{
			VerifyMethodOutput("Break",
@"while (a < 5)
{
	b = b + 1;
	break;
}
a = a + 1;");
		}
		public void Break()
		{
			int a = 0;
			int b = 1;
			while (a < 5)
			{
				b++;
				break;
			}
			a++;
		}

		[Test]
		public void IfBreakStatementTest()
		{
			VerifyMethodOutput("IfBreakStatement",
@"while (a < 5)
{
	if (a > 3)
		break;
	a = a + 1;
}
a = a + 1;",
@"while (a < 5)
{
	if (a <= 3)
		break;
	a = a + 1;
}
a = a + 1;");
		}
		public void IfBreakStatement()
		{
			int a = 0;
			while (a < 5)
			{
				if (a > 3)
					break;
				a++;
			}
			a++;
		}

		[Test]
		public void IfBreakIfBreakTest()
		{
			VerifyMethodOutput("IfBreakIfBreak",
@"a = 0;
b = 0;
while (a < 5)
{
	if (a > 3)
	{
		b = 2;
		break;
	}
	a = a + 1;
}
b = a;
while (b < 5)
{
	if (b > 3)
		a = 3;
	else
		b = b + 1;
}",
@"while (a < 5)
{
	if (a > 3)
	{
		b = 2;
		break;
	}
	a = a + 1;
}
b = a;
while (b < 5)
{
	if (b > 3)
	{
		a = 3;
		break;
	}
	b = b + 1;
}");
		}
		public void IfBreakIfBreak()
		{
			int a = 0;
			int b = 0;
			while (a < 5)
			{
				if (a > 3)
				{
					b = 2;
					break;
				}
				a++;
			}
			b = a;
			while (b < 5)
			{
				if (b > 3)
				{
					a = 3;
					break;
				}
				b++;
			}
		}

		[Test]
		public void IfBreakIfBreakStatementTest()
		{
			VerifyMethodOutput("IfBreakIfBreakStatement",
@"a = 0;
b = 0;
while (a < 5)
{
	if (a > 3)
	{
		b = 2;
		break;
	}
	a = a + 1;
}
b = a;
while (b < 5)
{
	if (b > 3)
	{
		a = 3;
		break;
	}
	b = b + 1;
}
b = a;");
		}
		public void IfBreakIfBreakStatement()
		{
			int a = 0;
			int b = 0;
			while (a < 5)
			{
				if (a > 3)
				{
					b = 2;
					break;
				}
				a++;
			}
			b = a;
			while (b < 5)
			{
				if (b > 3)
				{
					a = 3;
					break;
				}
				b++;
			}
			b = a;
		}

		[Test]
		public void IfStatementBreakTest()
		{
			VerifyMethodOutput("IfStatementBreak",
@"while (a < 5)
{
	a = a + 1;
	if (a > 3)
	{
		a = a - 1;
		if (a < 3)
			return;
	}
	else
		a = a + 1;
}",
@"while (a < 5)
{
	a = a + 1;
	if (a > 3)
	{
		a = a - 1;
		if (a < 3)
			break;
	}
	a = a + 1;
}");
		}
		public void IfStatementBreak()
		{
			int a = 0;
			while (a < 5)
			{
				a++;
				if (a > 3)
				{
					a--;
					if (a < 3)
						break;
				}
				a++;
			}
		}

		[Test]
		public void StatementIfBreakTest()
		{
			VerifyMethodOutput("StatementIfBreak",
@"var a;
a = 0;
while (a < 10)
{
	a = a + 1;
	if (a == 5)
		break;
}
a = a - 1;");
		}
		public void StatementIfBreak()
		{
			int a = 0;
			while (a < 10)
			{
				a++;
				if (a == 5)
					break;
			}
			a--;
		}

		[Test]
		public void StatementIfAndOrAndBreakStatementTest()
		{
			VerifyMethodOutput("StatementIfAndOrAndBreakStatement",
@"while (a < 10)
{
	a = a + 1;
	if (a == 5 && b == 3)
		break;
	if (c == 2 && b == c)
		return;
	else
		c = c - 1;
}", @"while (a < 10)
{
	a = a + 1;
	if (a == 5 && b == 3 || c == 2 && b == c)
		break;
	c = c - 1;
}");
		}
		public void StatementIfAndOrAndBreakStatement()
		{
			int a = 0;
			int b = 1;
			int c = 3;
			while (a < 10)
			{
				a++;
				if (a == 5 && b == 3 || c == 2 && b == c)
					break;
				c--;
			}
		}

		[Test]
		public void StatementIfAndOrAndBreakTest()
		{
			VerifyMethodOutput("StatementIfAndOrAndBreak",
@"while (a < 10)
{
	a = a + 1;
	if (a == 5 && b == 3)
		break;
	if (c != 2 || b != c)
		continue;
	return;
}", @"while (a < 10)
{
	a = a + 1;
	if (a == 5 && b == 3 || c == 2 && b == c)
		break;
}");
		}
		public void StatementIfAndOrAndBreak()
		{
			int a = 0;
			int b = 1;
			int c = 3;
			while (a < 10)
			{
				a++;
				if (a == 5 && b == 3 || c == 2 && b == c)
					break;
			}
		}

		[Test]
		public void StatementIfAndOrAndBreakReturnTest()
		{
			VerifyMethodOutput("StatementIfAndOrAndBreakReturn",
@"while (a < 10)
{
	a = a + 1;
	if (a == 5 && b == 3 || c == 2 && b == c)
		break;
	a = a - 1;
}
return c;");
		}
		public int StatementIfAndOrAndBreakReturn()
		{
			int a = 0;
			int b = 1;
			int c = 3;
			while (a < 10)
			{
				a++;
				if (a == 5 && b == 3 || c == 2 && b == c)
					break;
				a--;
			}
			return c;
		}

		[Test]
		public void StatementIfStatementBreakTest()
		{
			VerifyMethodOutput("StatementIfStatementBreak",
@"while (a < 10)
{
	a = a + 1;
	if (a != 5)
		continue;
	a = 11;
	return;
}", @"while (a < 10)
{
	a = a + 1;
	if (a != 5)
		continue;
	a = 11;
	break;
}");
		}
		public void StatementIfStatementBreak()
		{
			int a = 0;
			while (a < 10)
			{
				a++;
				if (a == 5)
				{
					a = 11;
					break;
				}
			}
		}

	}
}
